# 导包
import json
import app


# 封装读取登录接口的json参数化
def read_json_file():
    test_data = []
    # 指定参数化文件设置
    json_file = app.LEQ_OS + "/data/postman_login_canshuhua.json"
    # 打开文件
    with open(json_file, encoding="utf-8")as p:
        # 读取json文件,加载文件数据
        json_data = json.load(p)
        # 循环遍历取出每个大括号中的数据,并加工成测试数据
        for case_data in json_data:
            keywords = case_data.get("keywords")
            password = case_data.get("password")
            status_code = case_data.get("status_code")
            status = case_data.get("status")
            description = case_data.get("description")
            test_data.append((keywords, password, status_code, status, description))
    return test_data


# 封装公共断言
def common_assert(case, response, status_code, status, message):
    case.assertEqual(status_code, response.status_code)
    case.assertEqual(status, response.json().get("status"))
    case.assertIn(message, response.text)


